package ${configs.packagePath}.controller;

import ${configs.packagePath}.common.BaseController;
import ${configs.packagePath}.common.PageVO;
import ${configs.packagePath}.common.R;
import ${configs.packagePath}.pojo.${table.className};
import ${configs.packagePath}.service.${table.className}Service;
import ${configs.packagePath}.utils.RR;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <Description>
 * ${table.className}处理器
 * @author ${configs.author}
 * @version 1.0
 * @createDate ${date}
 * @see ${configs.packagePath}.controller
 */
@RequestMapping("${table.lowerName}")
@RestController
@Slf4j
public class ${table.className}Controller extends BaseController {
    @Autowired
    private ${table.className}Service ${table.lowerName}Service;

    /**
     * 查询所有
     * @return
     */
    @GetMapping
    public R findAll(){
        return RR.success(${table.lowerName}Service.findAll());
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public R findById(@PathVariable("id") Integer id){
        ${table.className} byId = ${table.lowerName}Service.findById(id);
        return RR.success(byId);
    }

    /**
     * 添加
     * @param ${table.lowerName}
     * @return
     */
    @PostMapping
    public R add(@RequestBody ${table.className} ${table.lowerName}){
        return RR.isOperation(${table.lowerName}Service.add(${table.lowerName}));
    }

    /**
     * 修改
     * @param ${table.lowerName}
     * @return
     */
    @PutMapping
    public R updateById(@RequestBody ${table.className} ${table.lowerName}){
        return RR.isOperation(${table.lowerName}Service.updateById(${table.lowerName}));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public R deleteById(@PathVariable("id") Integer id){
        return RR.isOperation(${table.lowerName}Service.deleteById(id));
    }


    /**
     * 分页
     * @return
     */
    @PostMapping("{page}/{size}")
    public R findPage(@PathVariable("page") Integer page,
                                @PathVariable("size") Integer size){
        return RR.success(PageVO.getInstance(${table.lowerName}Service.findPage(page,size)));
    }
}
